const validatePass=(seleteLists, valuekey="Label_Desc",ziduanKey)=>{
  return (rule, value, callback) => {
    seleteLists.forEach(item => {
      if(/(\r)|(\n)/g.test(item[valuekey])){
        item[valuekey]=item[valuekey].replace(/(\r)|(\n)/g, '')
      }
    });
    if(/(\r)|(\n)/g.test(value)){
      value=value.replace(/(\r)|(\n)/g, '')
    }
    const obj = seleteLists.some((item) => item[valuekey] == value);
    if (obj) {
      callback();
    } else {
      if(ziduanKey=="result_Type"){
        if (/^[A-Z]{1}[0-9a-zA-Z]+$/.test(value)) {
          callback();
        } else {
          callback(new Error("请输入内容，第一个字符必须是大写字母，后面的字符如果有必须是字母或数字"));
        }
      }else{
        if (/^[a-zA-Z<> ]+$/g.test(value)) {
          callback();
        } else {
          callback(new Error("输入内容不匹配下拉框时只能输入字母"));
        }
      }

    }
  };
}

export const commonRules=(seleteLists, valuekey,ziduanKey) => [
  {
    required: true,
    message: "请选择或输入内容",
    trigger: ["blur", "change"],
  },
  {
    validator: validatePass(seleteLists, valuekey,ziduanKey),
    trigger: ["blur", "change"],
  },
];

